package com.lvkerry.orderfood.repository;

import com.lvkerry.orderfood.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Kerry
 */

@Repository
public interface UserRepository extends JpaRepository<UserEntity, Long>, QueryByExampleExecutor<UserEntity> {

    /**
     * 通过用户名查询
     *
     * @param username
     * @return
     */
    UserEntity findByUsername(String username);

    /**
     * 通过用户名或者手机号查询
     *
     * @param username
     * @param phoneNumber
     * @return
     */
    UserEntity findByUsernameOrPhoneNumber(String username, String phoneNumber);

    /**
     * 删除用户
     *
     * @param username
     * @return
     */
    UserEntity removeByUsername(String username);

    /**
     * 查找所有没有禁用的用户
     *
     * @return
     */
    @Query("select u from UserEntity u where u.isDeleted = 0")
    List<UserEntity> findAllUnDeleted();

}
